const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    mode: 'development',
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].js'
    },
    module: {
        rules: [{
                test: /\.css$/,
                //loader: 'css-loader'
                //注意顺序：先执行css-loader
                //use: ['style-loader', 'css-loader']
                use: [{
                    loader: MiniCssExtractPlugin.loader,
                    options: {
                        //配置路径
                        publicPath: '../'
                    }
                }, 'css-loader']

            },
            {
                test: /\.(jpg|png|gif)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        name: 'imgss/[name].[ext]',
                        esModule: false,
                        limit: 10000000000
                    }
                }
            }, {
                test: /\.(html|htm)$/,
                loader: 'html-withimg-loader'
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html',
            filename: 'index.html'
        }),
        new MiniCssExtractPlugin({
            filename: 'css/[name].css',
        })
    ]
}